import { addressRecognition } from '@/api/address'
import { ref } from 'vue'
import { AddressParseResult } from '@/views/order/new/types'

export default () => {
  // 识别加载
  const addrParseLoading = ref(false)

  // 识别结果
  const addrParseResult = ref<AddressParseResult | null>(null)

  /**
   * 识别方法
   * @param {string} text - 被识别的文本
   */
  const addrParse = async (text: string) => {
    addrParseLoading.value = true
    const res = await addressRecognition(text)
    addrParseLoading.value = false
    addrParseResult.value = res.data.data.row
  }

  return {
    addrParseResult,
    addrParseLoading,
    addrParse,
  }
}
